﻿using System;
using System.Drawing;
using System.Web;

namespace dk.Helper.Base.Core
{
    public class VillageParser : IVillageParser
    {
        #region IVillageParser Members

        /// <summary>
        /// Creates the village.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public IVillage CreateVillage(string data)
        {
            try
            {
                string[] array = data.Split(',');
                int id = Convert.ToInt32(array[0]);
                string name = HttpUtility.UrlDecode(array[1]);
                var coord = new Point(Convert.ToInt32(array[2]), Convert.ToInt32(array[3]));
                int playerID = Convert.ToInt32(array[4]);
                int points = Convert.ToInt32(array[5]);
                int rank = Convert.ToInt32(array[6]);
                return new Village(id, name, coord, playerID, points, rank);
            }
            catch (Exception)
            {
                return null;
            }
        }

        #endregion
    }
}